﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WorkStation.Frameworks.EasyBus.Pipeline.Filters;

namespace WorkStation.Frameworks.EasyBus.Pipeline.Handles
{
    /// <summary>
    /// 异步处理器
    /// </summary>
    public class AsyncHandle : Handle
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="name">唯一标识</param>
        /// <param name="filter">过滤器</param>
        public AsyncHandle(string name = null, IFilter filter = null) : base(name, filter, -1) { }

        /// <summary>
        /// 异步执行
        /// </summary>
        /// <param name="context">执行上下文</param>
        /// <returns></returns>
        public Task<HandleResult> AsyncExecute(ActionContext context)
        {
            return Task<HandleResult>.Factory.StartNew(() => this.Execute(context));
        }
    }
}
